(function () {
  /* 轮播开始 */
  var banner = document.getElementsByClassName("banner")[0];
  var $carousel = $("#carousel");
  var $lis = $("#carousel ul li");
  var length = $lis.length;
  //定义定时器为空
  var timer = null;
  // 克隆第一张图片
  $lis.eq(0).clone().appendTo($("#carousel ul"));

  //计算图片比例
  var r = 1536 / 918;
  //获取当前视口宽度
  var width_s = document.documentElement.clientWidth;
  //获取图片缩放后的高
  var height_l = width_s / r;
  if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
    //赋值banner高度
    banner.style.height = height_l + "px";
  } else {
    banner.style.height = "320px";
  }
  //定义banner 宽度 使图片宽度等于banner 宽度
  var width_banner = banner.clientWidth;
  //定义变量，用于中转
  var left_l = 0;
  //定义信号量
  var idx = 0;
  //定义锁
  var lock = true;
  //添加swipeLeft
  $carousel[0].addEventListener("swipeRight", function () {
    clearInterval(timer);
    change_lunbo("rightHua");
    autoPlay_lunbo();
  })
  //添加swipeRight
  $carousel[0].addEventListener("swipeLeft", function () {
    clearInterval(timer);
    change_lunbo("leftHua");
    autoPlay_lunbo();
  })

  function change_lunbo(direction) {
    if (!lock) { return; }
    // 关锁
    lock = false;

    if (direction === "rightHua") {

      //右滑动
      idx--;
      //验证信号量
      if (idx < 0) {
        idx = length - 1;
        $carousel.css("left", -length * width_banner);
      }
      //拉动
      $carousel.animate({ left: -idx * width_banner }, 1000, function () {
        //开锁
        lock = true;
      })
    } else if (direction === "leftHua") {
      //左滑动
      idx++;
      //拉动
      $carousel.animate({ left: -idx * width_banner }, 1000, function () {
        //验证信号量
        if (idx > length - 1) {
          idx = 0;
          $carousel.css("left", 0);
        }
        //开锁
        lock = true;
      })
    }

  }

  function autoPlay_lunbo() {
    timer = setInterval(function () {
      change_lunbo("leftHua");
    }, 3000);
  }

  autoPlay_lunbo();
  /* 轮播结束 */














  /* 滚动条>设备高度,出现oHeader */
  var oHeader = document.getElementsByClassName("header")[0];
  var oSearch = document.getElementsByClassName("search")[0];
  var oLogin = document.getElementsByClassName("login")[0];
  var oLogin_span = oLogin.querySelector("span");
  // console.log(window.getComputedStyle(oLogin).getPropertyValue("color"));
  window.onscroll = function () {
    var y = 0;
    if (window.pageYOffset) {
      y = window.pageYOffset;
    } else {
      y = document.documentElement.scrolloHeader;
    }
    if (y > document.documentElement.clientHeight / 4) {
      oHeader.style.backgroundColor = '#fff';
      oSearch.style.backgroundColor = '#ececed';
      oLogin.style.color = "#000";
      oLogin_span.style.backgroundPosition = "1px -76px";
    } else {
      oHeader.style.backgroundColor = 'rgba(0, 0, 0, 0.1)';
      oSearch.style.backgroundColor = '#fff';
      oLogin.style.color = "#fff";
      oLogin_span.style.backgroundPosition = "1px -36px";
    }
  };



})()



